local skel = fk.CreateSkill{
  name = "lb__xuemian",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["lb__xuemian"] = "血冕",
  --[":lb__xuemian"] = "<b>锁定技</b>，结束阶段，若你本轮造成过伤害，你将体力值调整为本回合受到过伤害的角色数。场上仅剩一名其他角色时，此技能失效。",
  --9.2
  --[":lb__xuemian"] = "<b>锁定技</b>，结束阶段，若你本回合对场上半数（向下取整）角色造成过伤害，你回复1点体力，否则你失去1点体力。",
  --10.3
  [":lb__xuemian"] = "<b>锁定技</b>，结束阶段，若你本回合对场上半数（向下取整）角色造成过伤害，你回复1点体力，否则你失去1点体力。若你于回合内受到过伤害，你摸受到伤害数张牌。",


  ["$lb__xuemian1"] = "流淌吧，悬锋之血。",
  ["$lb__xuemian2"] = "怒吼吧，吾即纷争！",
}

skel:addEffect(fk.EventPhaseEnd, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.phase == Player.Finish
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = 0
    for _, to in ipairs(room:getAlivePlayers()) do
      if #room.logic:getEventsOfScope(GameEvent.Damage, 1, function (e)
        local damage = e.data
        return damage.from and damage.from == player and damage.to == to and not damage.prevented
      end, Player.HistoryTurn) > 0 then
        num = num + 1
      end
    end
    if num >= (#room:getAlivePlayers() // 2) then
      room:recover{
        who = player,
        num = 1,
        skillName = skel.name,
        recoverBy = player,
      }
    else
      room:loseHp(player, 1, skel.name)
    end
    if player:isAlive() then
      local damage = 0
      room.logic:getEventsOfScope(GameEvent.Damage, 99999, function(e)
        if e.data.to == player and not e.data.prevented then
          damage = damage + e.data.damage
        end
      end, Player.HistoryTurn)
      if damage > 0 then
        player:drawCards(damage, skel.name)
      end
    end
  end,
})

--[[
skel:addEffect(fk.EventPhaseEnd, {
  can_trigger = function(self, event, target, player, data)
    local logic = player.room.logic
    if player:hasSkill(skel.name) and target == player and data.phase == Player.Finish and
      #logic:getEventsOfScope(GameEvent.Damage,1,function (e)
          local damage = e.data
          return damage.from and damage.from == player
      end,Player.HistoryRound) > 0 then
      local tos = {}
      logic:getEventsOfScope(GameEvent.Damage,9999,function (e)
          table.insertIfNeed(tos,e.data.to)
      end,Player.HistoryTurn)
      if #tos ~= player.hp then
        event:setCostData(self,{num = #tos})
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = event:getCostData(self).num
    if num > player.hp then
      player.room:recover{
        who = player,
        num = num - player.hp,
        skillName = skel.name,
        recoverBy = player,
      }
    else
      room:loseHp(player,player.hp - num, skel.name)
    end
  end,
})
  --8.30

skel:addEffect("invalidity", {
  invalidity_func = function (self, from, skill)
    return skill.name == skel.name and 
    #table.filter(Fk:currentRoom().alive_players, function (to)
      return to ~= from
    end) == 1
  end,
})
--]]
return skel